package cn.lili.controller.promotion;

import cn.lili.common.security.AuthUser;
import cn.lili.common.security.context.UserContext;
import cn.lili.common.utils.ResultUtil;
import cn.lili.common.vo.ResultMessage;
import cn.lili.modules.page.entity.dos.Article;
import cn.lili.modules.promotion.entity.vos.BlindboxArticleRelVO;
import cn.lili.modules.promotion.service.BlindboxArticleRelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;
import java.util.Objects;

@RestController
@Api(tags = "盲盒统计接口")
@RequestMapping("/promotion/blindbox/articlerel")
@RequiredArgsConstructor
public class BlindboxArticleRelController {

    private final BlindboxArticleRelService blindboxArticleRelService;

    @ApiOperation(value = "同意抽奖协议")
    @PutMapping("/agree")
    public ResultMessage<Object> updateAgree(@RequestBody BlindboxArticleRelVO blindboxArticleRelVO) {
        AuthUser currentUser = Objects.requireNonNull(UserContext.getCurrentUser());
        blindboxArticleRelService.updateAgree(currentUser.getExtendId(),blindboxArticleRelVO);
        return ResultUtil.data(null);
    }

    @ApiOperation(value = "通过类型获取文章")
    @ApiImplicitParam(name = "type", value = "文章类型", required = true, paramType = "path")
    @GetMapping(value = "/type/all/{type}")
    public ResultMessage<List<Article>> getAllByType(@NotNull(message = "文章类型") @PathVariable("type") String type) {
        AuthUser currentUser = Objects.requireNonNull(UserContext.getCurrentUser());
        return ResultUtil.data(blindboxArticleRelService.getAllByType(currentUser.getExtendId(),type));
    }
}
